//封装请求

//引进提示
import {errdata} from 'api/errdata.js'
import store from '../store/store.js'

//GET
const listing=function(urling){
	return new Promise((resolve,reject)=>{
		uni.request({
			url:urling,
			method:'GET',
			header:{
				userToken: uni.getStorageSync('token')
			}
		})
		.then(res=>{
			if(res.data.code === 401){
				// const errs='请登录'
				// errdata.errlist(errs)
				uni.clearStorageSync()
				uni.switchTab({
					url: '../../pages/my/index'
				})
			}else{
				resolve(res)
			}
		})
		.catch(err=>{
			const errs='服务器错误 请稍后再试'
			errdata.errlist(errs)
			reject(err)
		})
	})
}
//POST
const publicing=function(urling,shopdata){
	return new Promise((resolve,reject)=>{
		uni.request({
			url:urling,
			method:'POST',
			data:shopdata,
			header:{
				userToken: uni.getStorageSync('token')
			}
		})
		.then(res=>{
			if(res.data.code === 401){
				// const errs='请登录'
				// errdata.errlist(errs)
				uni.clearStorageSync()
				uni.switchTab({
					url: '../../pages/my/index'
				})
			}else{
				resolve(res)
			}
		})
		.catch(err=>{
			const errs='服务器错误 请稍后再试'
			errdata.errlist(errs)
			reject(err)
		})
	})
}

export{listing,publicing}